/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.hualu.zks.GUI;


import com.hualu.zks.CommonUtils.Globalparameters;
import com.hualu.zks.Model.Node;
import com.hualu.zks.Dao.NodeDao;
import com.hualu.zks.GUI.JFrame_Node;
import static com.hualu.zks.GUI.JFrame_Node.nodeList;
import java.awt.Toolkit;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class JFrame_NodeEdit extends javax.swing.JFrame {
//	public static NoteJFrame notejframe;
	public static Node note;
	public static JFrame_Node notejframe;
    /**
     * Creates new form ChangeNoteJFrame
     */
    public JFrame_NodeEdit(Node note,JFrame_Node notejframe) {
        initComponents();
        JFrame_NodeEdit.note=note;
        JFrame_NodeEdit.notejframe = notejframe;
        setText(note);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton_Enter = new javax.swing.JButton();
        jButton_Cancel = new javax.swing.JButton();
        jLabel_NoteName = new javax.swing.JLabel();
        jLabel_IPID = new javax.swing.JLabel();
        jTextField_NoteName = new javax.swing.JTextField();
        jTextField_IPID = new javax.swing.JTextField();
        jLabel_biaoti4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("节点修改");
        setIconImage(Toolkit.getDefaultToolkit().getImage("pic\\bfhl.jpg"));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jButton_Enter.setText("确定");
        jButton_Enter.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_EnterMouseClicked(evt);
            }
        });

        jButton_Cancel.setText("取消");
        jButton_Cancel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_CancelMouseClicked(evt);
            }
        });

        jLabel_NoteName.setText("节点名称");

        jLabel_IPID.setText(" IP地址");

        jTextField_IPID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_IPIDActionPerformed(evt);
            }
        });

        jLabel_biaoti4.setFont(new java.awt.Font("华文行楷", 0, 24)); // NOI18N
        jLabel_biaoti4.setText("修改节点");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel_biaoti4)
                .addGap(0, 384, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(99, 99, 99)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(8, 8, 8)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel_NoteName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel_IPID, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGap(43, 43, 43))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jButton_Enter, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(27, 27, 27)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(30, 30, 30)
                            .addComponent(jButton_Cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jTextField_NoteName, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField_IPID, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(114, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel_biaoti4)
                .addGap(0, 290, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(66, 66, 66)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel_NoteName)
                        .addComponent(jTextField_NoteName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(24, 24, 24)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel_IPID)
                        .addComponent(jTextField_IPID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 78, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton_Enter)
                        .addComponent(jButton_Cancel))
                    .addGap(67, 67, 67)))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents
    
    private void  setText(Node note) {
    	jTextField_NoteName.setText(note.getName());
    	jTextField_IPID.setText(note.getIPAdd());
	}

    private void jButton_CancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_CancelMouseClicked
        // TODO add your handling code here:
        this.dispose();
        notejframe.setVisible(true);
    }//GEN-LAST:event_jButton_CancelMouseClicked
                                             
    private void jTextField_IPIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_IPIDActionPerformed
    	// TODO add your handling code here:
    }//GEN-LAST:event_jTextField_IPIDActionPerformed

    private void jButton_EnterMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_EnterMouseClicked
        // TODO add your handling code here:
        if((jTextField_NoteName.getText().equals(note.getName()))&&(jTextField_IPID.getText().equals(note.getIPAdd())))
            {
               JOptionPane.showMessageDialog(null, Globalparameters.strNoChange,Globalparameters.strInformation, JOptionPane.INFORMATION_MESSAGE);                
               return;
            }else if((!jTextField_NoteName.getText().equals(note.getName()))&&!(jTextField_IPID.getText().equals(note.getIPAdd())))
            {
               if (NodeDao.isNodeNameValide(jTextField_NoteName.getText())) {
                    JOptionPane.showMessageDialog(null, Globalparameters.strNameValide, Globalparameters.strInformation, JOptionPane.INFORMATION_MESSAGE);                
                    return;
               }
                if (NodeDao.isNodeIpValide(jTextField_IPID.getText())) {
                    JOptionPane.showMessageDialog(null, Globalparameters.strIpValide, Globalparameters.strInformation, JOptionPane.INFORMATION_MESSAGE);                
                    return;
            }
        }else if(jTextField_IPID.getText().equals(note.getIPAdd())){
            if (NodeDao.isNodeNameValide(jTextField_NoteName.getText())) {
                   JOptionPane.showMessageDialog(null, Globalparameters.strNameValide, Globalparameters.strInformation, JOptionPane.INFORMATION_MESSAGE);                
                   return;
            }
        }else if(jTextField_NoteName.getText().equals(note.getName())){
            if (NodeDao.isNodeIpValide(jTextField_IPID.getText())) {
                   JOptionPane.showMessageDialog(null, Globalparameters.strIpValide, Globalparameters.strInformation, JOptionPane.INFORMATION_MESSAGE);                
                   return;
            }
        }
        Node noteNew = new Node();
        noteNew.setNodeId(note.getNodeId());
        noteNew.setName(jTextField_NoteName.getText());
        noteNew.setIPAdd(jTextField_IPID.getText());
        notejframe.nodeDao.editNode(noteNew);
        this.dispose();
        notejframe.Refresh();
        notejframe.setVisible(true);
    }//GEN-LAST:event_jButton_EnterMouseClicked

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        this.dispose();
        notejframe.setVisible(true);
    }//GEN-LAST:event_formWindowClosing

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JFrame_NodeEdit.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JFrame_NodeEdit.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JFrame_NodeEdit.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JFrame_NodeEdit.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFrame_NodeEdit(note,notejframe).setVisible(true);
            }
        });
        

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_Cancel;
    private javax.swing.JButton jButton_Enter;
    private javax.swing.JLabel jLabel_IPID;
    private javax.swing.JLabel jLabel_NoteName;
    private javax.swing.JLabel jLabel_biaoti4;
    private javax.swing.JTextField jTextField_IPID;
    private javax.swing.JTextField jTextField_NoteName;
    // End of variables declaration//GEN-END:variables
}
